package loan.calc.calculator.instalment;


import loan.calc.exception.CalcualatorException;
import loan.calc.constant.dict.RepayMethodDictEnum;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.stereotype.Component;

/**
 * 期供计算器
 */
@Component
public class InstalmentCalculatorFactory extends ApplicationObjectSupport {

    public InstalmentCalculator loadInstalmentCalculator(RepayMethodDictEnum repayMethod, InstalmentCalculatorParamDTO instalmentCalculatorParam) {
        InstalmentCalculator instalmentCalculator = getApplicationContext().getBeanProvider(InstalmentCalculator.class)
                .stream()
                .filter(i -> i.support() == repayMethod)
                .findAny().orElseThrow(() -> new CalcualatorException("Unsupported repayment calculator for repayment method: " + repayMethod.getDescription()));
        return instalmentCalculator;
    }
}
